/*
 * Vigas.cpp
 *
 *  Created on: 24/07/2013
 *      Author: juan
 */

#include "Vigas.h"
#define CANT_VIGAS 6
#define ANCHO_EDF 15
#ifndef CANT_PISOS
#define CANT_PISOS 5
#endif

Vigas::Vigas(GLuint program):Figure(program) {
	cubos = new std::list<Cube*>();
	crear_cubos(program,CANT_PISOS);
}

void Vigas::crear_cubos(GLuint program, int pisos) {
	float desplazamiento = (ANCHO_EDF/CANT_VIGAS);
	for (int i=0; i<CANT_VIGAS; i++) {
		Cube* auxiliar = new Cube(program);
		auxiliar->traslate(glm::vec3(-6.0f + (i*desplazamiento), 2.9f, 3.0f * pisos));
		auxiliar->scale(glm::vec3(0.3f, 0.3f, pisos * 6.0f));
		cubos->push_back(auxiliar);
		auxiliar->rotate(45,glm::vec3(0.0,0.0,1.0));
	}
}

Vigas::~Vigas() {
	for (std::list<Cube*>::iterator it = cubos->begin(); it != cubos->end(); it++) {
			Cube* aux = (*it);
			delete aux;
		}
	delete cubos;
}

void Vigas::draw(GLuint program, glm::mat4 & world_matrix) {
	glm::mat4 matriz = world_matrix * this->model_matrix;

// Normal Matrix
	glm::mat3 normal_matrix = glm::mat3(1.0f);
	if (this->view_matrix != NULL) {
		glm::mat4 aux = (*this->view_matrix) * world_matrix;
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				normal_matrix[i][j] = aux[i][j];
	}
	for (std::list<Cube*>::iterator it = cubos->begin(); it != cubos->end(); it++) {
		Cube* aux = (*it);
		//aux->activate_texture();
		aux->draw(program,world_matrix);
	}
}

void Vigas::set_texture_id(GLuint texture) {
	for (std::list<Cube*>::iterator it = cubos->begin(); it != cubos->end(); it++) {
		Cube* aux = (*it);
		aux->set_texture_id(texture);
	}
}
